﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.Net;
using System.IO;



namespace Demo2
{
    public partial class Form1 : Form
    {
        private string url = "http://utf8.sms.webchinese.cn/?";//发送短信平台网址SMS
        private string strUid = "Uid=";//注册的SMS平台的账号ID
        private string strKey = "&key=d41d8cd98f00b204e980";//注册的SMS平台的接口密匙
        private string strMob = "&smsMob=";//手机号码
        private string strContent = "&smsText=";

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtUserName.Text) && !string.IsNullOrEmpty(txtAttnNum.Text)
                && !string.IsNullOrEmpty(txtContent.Text))
            {
                url = url + strUid + txtUserName.Text + strKey + strMob + txtAttnNum.Text + strContent + txtContent.Text;
                string Result = GetHtmlFromUrl(url);
                MessageBox.Show(Result);
            }
        }
        public string GetHtmlFromUrl(string url)
        {
            string strRet = null;
            if (string.IsNullOrEmpty(url))
            {
                return strRet;
            }
            string targeturl = url.Trim().ToString();
            try
            {
                HttpWebRequest hr = (HttpWebRequest)WebRequest.Create(targeturl);
                hr.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
                hr.Method = "GET";
                hr.Timeout = 30 * 60 * 1000;
                WebResponse hs = hr.GetResponse();
                Stream sr = hs.GetResponseStream();
                StreamReader ser = new StreamReader(sr, Encoding.Default);
                strRet = ser.ReadToEnd();
            }
            catch (Exception)
            {

                strRet = null;
            }
            return strRet;
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }
    }
}
